package com.my.signature.test;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author timo 2021/3/2
 */
@RestController
@RequestMapping("example")
public class ExampleController {
    //curl -X POST \
    //  'http://localhost:8080/example/test/1/2?var3=3&var4=4' \
    //  -H 'Content-Type: application/json' \
    //  -H 'X-SIGN: 0e56acaa4b7c2983b885c329f4c524a839574e207fd8603c1c142c1beca035b2' \
//      -d '{
//        "name": "hjzgg",
//        "age": 26
//    }'
    @PostMapping(value = "test/{var1}/{var2}", produces = MediaType.ALL_VALUE)
    public String myController(@PathVariable String var1, @PathVariable String var2, @RequestParam String var3, @RequestParam String var4,
                               @RequestBody User user) {
        return String.join(",", var1, var2, var3, var4, user.toString());
    }

    private static class User {
        private String name;
        private int age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

    }
}
